package com.util;

import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import net.sf.json.JSONObject;
public class LoggerUtil {

	public static String getParams(HttpServletRequest request) {
		JSONObject json=new JSONObject();
		String uri=request.getRequestURI();
		json.put("uri", uri);
		
		//json.put("deviceId", request.getParameter("deviceId"));
		json.put("mId", request.getParameter("mId"));
		json.put("deviceId", request.getParameter("deviceId"));
		json.put("deviceType", request.getParameter("deviceType"));
		String curPge=request.getParameter("curPage");
		json.put("curPage", curPge);
		String pageSize=request.getParameter("pageSize");
		json.put("pageSize", pageSize);
		String value=json.toString();
		return value;
	}
	public static String getKey(Map<String, String> params)
		 {
		Set<String> keysSet = params.keySet();
		Object[] keys = keysSet.toArray();
		Arrays.sort(keys);
		JSONObject jsonObject=new JSONObject();
		for (Object key : keys) {
			Object value = params.get(key);
			String valueString = "";
			if (null != value) {
				valueString = String.valueOf(value);
			}
			jsonObject.put(key, valueString);
		}
		return  jsonObject.toString();
	}
	
	public static void backlogsSuccess(JSONObject logs,Logger logger){
		logs.put("result", Domain.success_logs);
		logger.debug(logs.toString());
	}
	public static void backlogsFalseNOData(JSONObject logs,Logger logger){
		logs.put("result", Domain.false_no_data);
		logger.debug(logs.toString());
	}
	public static void backlogsFalseNOUser(JSONObject logs,Logger logger){
		logs.put("result", Domain.false_no_user);
		logger.debug(logs.toString());
	}
	public static void backlogsFalseError(JSONObject logs,Logger logger,Exception e){
		logs.put("result", Domain.false_systerm_error);
		logger.error(logs.toString(),e);
	}
	public static void backlogsFalseStr(JSONObject logs,Logger logger,String value){
		logs.put("result", value);
		logger.debug(logs.toString());
	}
	
	public static void main(String[] args) {
		JSONObject json=new JSONObject();
		System.err.println(json.get("hhh"));
	}
}
